package cn.tedu.collection;/**
 * @Author 金帮嘉诚 @Date 2021-06-23 星期三 20:27
 */
/*本类用于测试List接口的子类ArrayList*/

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * 知识点
 * ArrayList的方法
 * get
 * contains
 * indexOf
 * lastIndexOf
 * remove 注意删除时的参数类型要和List的元素类型一致
 */
public class TestArrayList {
    public static void main(String[] args) {
        ArrayList<Integer> al1 = new ArrayList<>();
        al1.add(1);
        al1.add(11);
        al1.add(111);
        al1.add(1111);
        al1.add(11111);
        al1.add(111111);
        al1.add(1);

        System.out.println("al1.get(1) = " + al1.get(1));
        System.out.println("al1.contains(1) = " + al1.contains(1));
        System.out.println("al1.size() = " + al1.size());
        System.out.println("al1.indexOf(1) = " + al1.indexOf(1));
        System.out.println("al1.lastIndexOf(1) = " + al1.lastIndexOf(1));
        System.out.println("al1 = " + al1);
        System.out.println("al1.remove(1) = " + al1.remove(1));
        System.out.println("al1.remove(Integer.valueOf(1)) = " + al1.remove(Integer.valueOf(1)));

        for (int i = 0; i < al1.size(); i++) {
            System.out.println("al1.get(i) = " + al1.get(i));
        }

        for (Integer i:al1
             ) {
            System.out.println(i);
        }

        Iterator<Integer> it1=al1.iterator();
        while (it1.hasNext()){
            System.out.println("it1.next() = " + it1.next());
        }

        ListIterator<Integer> lit1=al1.listIterator();
        while (lit1.hasNext()){
            System.out.println(lit1.next());
        }

    }
}
